/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.client.ZEmailAddress;
/*     */ import com.zimbra.client.ZFolder;
/*     */ import com.zimbra.client.ZFolder.View;
/*     */ import com.zimbra.client.ZMailbox;
/*     */ import com.zimbra.client.ZMailbox.ZOutgoingMessage;
/*     */ import com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart;
/*     */ import com.zimbra.client.ZMessage;
/*     */ import com.zimbra.client.ZMessageHit;
/*     */ import com.zimbra.client.ZSearchHit;
/*     */ import com.zimbra.client.ZSearchParams;
/*     */ import com.zimbra.client.ZSearchResult;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.soap.type.SearchSortBy;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestDraftCount
/*     */ {
/*     */   private static final String USER_NAME = "testuser123";
/*     */   private static ZMailbox mbox;
/*     */   private static final int numMsgs = 5;
/*     */   
/*     */   @BeforeClass
/*     */   public static void setUp()
/*     */     throws ServiceException
/*     */   {
/*  49 */     TestUtil.createAccount("testuser123");
/*  50 */     mbox = TestUtil.getZMailbox("testuser123");
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void tearDown() throws ServiceException {
/*  55 */     TestUtil.deleteAccount("testuser123");
/*     */   }
/*     */   
/*     */   private void deleteFromQuery(String query) throws Exception
/*     */   {
/*  60 */     ZSearchParams params = new ZSearchParams(query);
/*  61 */     params.setTypes("message");
/*  62 */     params.setOffset(0);
/*  63 */     ZSearchResult results = mbox.search(params);
/*  64 */     for (ZSearchHit hit : results.getHits()) {
/*  65 */       ZMessageHit msg = (ZMessageHit)hit;
/*  66 */       mbox.deleteMessage(hit.getId());
/*     */     }
/*     */   }
/*     */   
/*     */   private void checkMessageCount(String query, int expected) throws Exception
/*     */   {
/*  72 */     ZSearchParams params = new ZSearchParams(query);
/*  73 */     params.setTypes("message");
/*  74 */     params.setOffset(0);
/*  75 */     params.setSortBy(SearchSortBy.rcptAsc);
/*  76 */     ZSearchResult results = mbox.search(params);
/*  77 */     Assert.assertEquals(expected, results.getHits().size());
/*  78 */     params.setSortBy(SearchSortBy.rcptDesc);
/*  79 */     results = mbox.search(params);
/*  80 */     Assert.assertEquals(expected, results.getHits().size());
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testAllDraftsHaveRecipients() throws Exception { ZMessage saved;
/*  85 */     for (int i = 0; i < 5; i++) {
/*  86 */       ZMailbox.ZOutgoingMessage msg = new ZMailbox.ZOutgoingMessage();
/*  87 */       msg.setMessagePart(new ZMailbox.ZOutgoingMessage.MessagePart("text/plain", "test body " + i));
/*  88 */       msg.setSubject("test message " + i);
/*  89 */       List<ZEmailAddress> addresses = new ArrayList();
/*  90 */       addresses.add(new ZEmailAddress("testuser" + i, null, null, "t"));
/*  91 */       msg.setAddresses(addresses);
/*  92 */       saved = mbox.saveDraft(msg, null, "6");
/*     */     }
/*  94 */     checkMessageCount("in:drafts", 5);
/*  95 */     deleteFromQuery("in:drafts");
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testSomeDraftsHaveRecipients() throws Exception { ZMessage saved;
/* 100 */     for (int i = 0; i < 5; i++) {
/* 101 */       ZMailbox.ZOutgoingMessage msg = new ZMailbox.ZOutgoingMessage();
/* 102 */       msg.setMessagePart(new ZMailbox.ZOutgoingMessage.MessagePart("text/plain", "test body " + i));
/* 103 */       msg.setSubject("test message " + i);
/* 104 */       List<ZEmailAddress> addresses = new ArrayList();
/* 105 */       if (i % 2 == 0) {
/* 106 */         addresses.add(new ZEmailAddress("testuser" + i, null, null, "t"));
/* 107 */         msg.setAddresses(addresses);
/*     */       }
/* 109 */       saved = mbox.saveDraft(msg, null, "6");
/*     */     }
/* 111 */     checkMessageCount("in:drafts", 5);
/* 112 */     deleteFromQuery("in:drafts");
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testInboxCount() throws Exception {
/* 117 */     for (int i = 0; i < 5; i++) {
/* 118 */       TestUtil.addMessage(mbox, "test content " + i, "2");
/*     */     }
/* 120 */     checkMessageCount("in:inbox", 5);
/* 121 */     deleteFromQuery("in:inbox");
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testCustomFolderCount() throws Exception {
/* 126 */     String folderName = "Test Custom Folder";
/* 127 */     ZFolder folder = mbox.createFolder("1", folderName, ZFolder.View.message, null, null, null);
/* 128 */     for (int i = 0; i < 5; i++) {
/* 129 */       TestUtil.addMessage(mbox, "test content " + i, folder.getId());
/*     */     }
/* 131 */     checkMessageCount("in:\"" + folderName + "\"", 5);
/* 132 */     mbox.deleteFolder(folder.getId());
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testMixedFolderCount() throws Exception
/*     */   {
/* 138 */     for (int i = 0; i < 5; i++) {
/* 139 */       TestUtil.addMessage(mbox, "test content " + i, "2");
/*     */     }
/*     */     ZMessage saved;
/* 142 */     for (int i = 0; i < 5; i++) {
/* 143 */       ZMailbox.ZOutgoingMessage msg = new ZMailbox.ZOutgoingMessage();
/* 144 */       msg.setMessagePart(new ZMailbox.ZOutgoingMessage.MessagePart("text/plain", "test body " + i));
/* 145 */       msg.setSubject("test message " + i);
/* 146 */       List<ZEmailAddress> addresses = new ArrayList();
/* 147 */       if (i % 2 == 0) {
/* 148 */         addresses.add(new ZEmailAddress("testuser" + i, null, null, "t"));
/* 149 */         msg.setAddresses(addresses);
/*     */       }
/* 151 */       saved = mbox.saveDraft(msg, null, "6");
/*     */     }
/* 153 */     checkMessageCount("in:inbox OR in:drafts", 10);
/* 154 */     deleteFromQuery("in:inbox OR in:drafts");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestDraftCount.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */